namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using Contracts.Interfaces;

    
    public sealed class RemoteArmorRepairAmount<T> : FeatureBase<object>
    {
        public RemoteArmorRepairAmount(){}

        public RemoteArmorRepairAmount(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Repair amount"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.RemoteArmorRepairAmount; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_hp; } }


        public override void SetModifiedValue(Contracts.Interfaces.IAgent agent, Contracts.Interfaces.IRobot robot)
        {
            if(agent ==null || robot ==null) return;

            double extension = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType);
            double robotBonus = robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Module, this.FeatureType);

            double temp = (double)Value * (1 + (extension + robotBonus));

            temp = robot.Modules.Aggregate(temp, (current, modifier) => current * (1 + Math.Abs(modifier.Value)), FeatureTypesEnum.Module, this.FeatureType, ModuleGroupsEnum.ArmorRepairersTunings);

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 2);

        }
    }
}